package com.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.common.utils.DateUtil;
import com.entity.SharesDetail;
import com.entity.SharesGdnum;
import com.mapper.SharesGdnumMapper;
import com.service.SharesDetailService;
import com.service.SharesGdnumService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wty
 * @since 2021-11-21
 */
@Service
public class SharesGdnumServiceImpl extends ServiceImpl<SharesGdnumMapper, SharesGdnum> implements SharesGdnumService {

    @Autowired
    private SharesDetailService sharesDetailService;


    @Override
    public void subNum() {

        Wrapper<SharesGdnum> wr=new EntityWrapper<>();
        wr.gt("time", DateUtil.getYMDByDaysAgo(15)+" 00:00:00");
        List<SharesGdnum> gdnums = this.selectList(wr);
        if(!CollectionUtils.isEmpty(gdnums)){
            gdnums = gdnums.stream().filter(x -> new BigDecimal(x.getHolderNumRatio()).compareTo(new BigDecimal(-10)) == -1).collect(Collectors.toList());
        }else{
            return;
        }

        Wrapper<SharesDetail> swr=new EntityWrapper<>();
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(swr);

        Map<String,SharesDetail> map=new HashMap<>();
        for (SharesDetail sharesDetail : sharesDetails) {
            String code = sharesDetail.getCode().substring(2);
            map.put(code,sharesDetail);
        }
        for (SharesGdnum gdnum : gdnums) {
            String code = gdnum.getCode();
            SharesDetail sharesDetail = map.get(code);
            if(null!=sharesDetail){
                sharesDetail.setType("1");
            }
        }
    }
}
